<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <!--0:引入 vue.js-->
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
  </head>
  <body>
    <!--1：界面视图  View -->
    <div id="app">
      <input type="text" v-model:value="keywords" />
      <button @click = "search">搜索一下</button>
      <h4>输入的关键字是：{{this.keywords}}</h4>
    </div>
    <script>
      //2:数据模型  Model
    //   var data = {
    //     keywords: "macbook 15",
    //   };

      //3:控制 （界面跟数据 同步   ViewModel
      var vm = new Vue({
        el: "#app",
        data: {
          keywords: "macbook 15",
        },

        methods:{
            search(){
                console.log(`调用了search函数，搜索的字符串是：${this.keywords}`);
            }
        },

        watch:{
            //函数名=要监控的变量名
            keywords(){
                this.search();
            }

        }


      });
    </script>
  </body>
</html>
